package com.bibrApp.difu.actvity.connect_mvp;


import androidx.annotation.NonNull;

import com.bibrApp.difu.R;
import com.bibrApp.difu.proto2javabean.FeatureBean;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.ArrayList;

public class ConnectAdapter extends BaseQuickAdapter<FeatureBean, BaseViewHolder> {

    int selected = -1;
    int loadingIndex = -1;

    public ConnectAdapter() {
        super(R.layout.item_connect, new ArrayList<>());
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, FeatureBean item) {
        helper.setGone(R.id.ll_menu, selected == getData().indexOf(item));
        helper.setGone(R.id.item_loading, loadingIndex == getData().indexOf(item));
        helper.setText(R.id.item_name, item.getLabel());
        /*if (Build.VERSION.SDK_INT > 21) {
            helper.setText(R.id.item_name, item.getLabel());
        } else {
            helper.setText(R.id.item_name, item.getProductId());
        }*/
        helper.addOnClickListener(R.id.item_connect);
        helper.addOnClickListener(R.id.item_cancel);
    }

    public void changeSelected(int selected) {
        this.selected = selected;
        notifyDataSetChanged();
    }

    public void changeLoading(int index) {
        this.loadingIndex = index;
        this.selected = -1;
        notifyDataSetChanged();
    }
}
